ac6735
@@ -3324,20 +3324,30 @@
private int describeTable(Hive db, DescTableDesc descTbl) throws HiveException,
         if (tbl.isPartitioned() && part == null) {
           // No partitioned specified for partitioned table, lets fetch all.
           Map<String,String> tblProps = tbl.getParameters() == null ? new HashMap<String,String>() : tbl.getParameters();
-          PartitionIterable parts = new PartitionIterable(db, tbl, null, conf.getIntVar(HiveConf.ConfVars.METASTORE_BATCH_RETRIEVE_MAX));
+          Map<String, Long> valueMap = new HashMap<>();
+          Map<String, Boolean> stateMap = new HashMap<>();
           for (String stat : StatsSetupConst.supportedStats) {
-            boolean state = true;
-            long statVal = 0l;
-            for (Partition partition : parts) {
-              Map<String,String> props = partition.getParameters();
-              state &= StatsSetupConst.areBasicStatsUptoDate(props);
+            valueMap.put(stat, 0L);
+            stateMap.put(stat, true);
+          }
+          PartitionIterable parts = new PartitionIterable(db, tbl, null, conf.getIntVar(HiveConf.ConfVars.METASTORE_BATCH_RETRIEVE_MAX));
+          int numParts = 0;
+          for (Partition partition : parts) {
+            Map<String, String> props = partition.getParameters();
+            Boolean state = StatsSetupConst.areBasicStatsUptoDate(props);
+            for (String stat : StatsSetupConst.supportedStats) {
+              stateMap.put(stat, stateMap.get(stat) && state);
               if (props != null && props.get(stat) != null) {
-                statVal += Long.parseLong(props.get(stat));
+                valueMap.put(stat, valueMap.get(stat) + Long.parseLong(props.get(stat)));
               }
             }
-            StatsSetupConst.setBasicStatsState(tblProps, Boolean.toString(state));
-            tblProps.put(stat, String.valueOf(statVal));
+            numParts++;
+          }
+          for (String stat : StatsSetupConst.supportedStats) {
+            StatsSetupConst.setBasicStatsState(tblProps, Boolean.toString(stateMap.get(stat)));
+            tblProps.put(stat, valueMap.get(stat).toString());
           }
+          tblProps.put(StatsSetupConst.NUM_PARTITIONS, Integer.toString(numParts));
           tbl.setParameters(tblProps);
         }
       } else {
